const app = getApp()
Page({
  data: {
    fontSetSize: 'small', // 用户设置的字体大小（'small'：小，'middle'：中，'large'：大）
  },

  /**
   * 获取我的收藏
   */
  getCollection () {
    let token = wx.getStorageSync('token')
    app.http({
      config: {
        url: '/api/User/my_collection',
        data: {
          token
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'collectionRes')
      this.setData({
        collectionList: res.data.data.data
      })
    }).catch(err => {
      console.log(err, 'collectionErr')
    })
  },

  /**
   * 取消收藏
   */
  handleDeleteCollection (e) {
    let token = wx.getStorageSync('token')
    let collection_id = e.currentTarget.dataset.collection_id
    app.http({
      config: {
        url: '/api/User/del_collection',
        data: {
          token,
          collection_id
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'deleteCollectionRes')
      this.getCollection()
    }).catch(err => {
      console.log(err, 'deleteCollectionErr')
    })
  },

  onLoad: function (options) {
    this.getCollection()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let fontSetSize = wx.getStorageSync('fontSetSize') // 本地缓存中用户设置的字体大小
    if (fontSetSize) {
      this.setData({
        fontSetSize
      })
    }
  },

});